package com.portal.cwegportal.controller;
import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;

import com.portal.cwegportal.input.usermailaccount.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("api/services/portal/usermailaccount")
@Api(description = "用户邮箱账户信息API")
public class UserMailAccountController {
    @Autowired
    com.portal.cwegportal.service.UserMailAccountService userMailAccountService;
    @ApiOperation(value = "维护用户邮箱账户信息", notes = "维护用户邮箱账户信息",produces = "application/json")
    @PostMapping("/editUserMailAccount")
    public ResponseEntity<JsonResult> manageUserMailAccount(@RequestBody EditUserMailAccountInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"维护用户邮箱账户信息",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(userMailAccountService.ManageUserMailAccount(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

 /*   @ApiOperation(value = "创建用户邮箱账户信息", notes = "创建用户邮箱账户信息", produces = "application/json")
    @PostMapping("/createUserMailAccount")
    public ResponseEntity<JsonResult> createUserMailAccount(@RequestBody CreateUserMailAccountInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            r.setResult(userMailAccountService.createUserMailAccount(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除用户邮箱账户信息", notes = "删除用户邮箱账户信息",produces = "application/json")
    @PostMapping("/deleteUserMailAccount")
    public ResponseEntity<JsonResult> deleteUserMailAccount(@RequestBody DeleteUserMailAccountInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(userMailAccountService.deleteUserMailAccount(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "修改用户邮箱账户信息", notes = "修改用户邮箱账户信息",produces = "application/json")
    @PostMapping("/editUserMailAccount")
    public ResponseEntity<JsonResult> editUserMailAccount(@RequestBody EditUserMailAccountInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(userMailAccountService.editUserMailAccount(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }



    @ApiOperation(value = "搜索用户邮箱账户信息", notes = "搜索用户邮箱账户信息",produces = "application/json")
    @PostMapping("/getUserMailAccount")
    public ResponseEntity<JsonResult> getUserMailAccount(@RequestBody GetUserMailAccountsInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            r.setResult(userMailAccountService.getUserMailAccounts(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载用户邮箱账户信息信息", notes = "加载用户邮箱账户信息信息",produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> pageLoad(@RequestBody PageLoadInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(userMailAccountService.pageLoad(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }*/
}
